import torch
import cv2
from image_split import split_image  # 导入 image_split.py 中的 split_image 函数

# 加载 torchscript 模型
model = torch.jit.load('model.pt')

# 读取原始图像
image_path = 'image.jpg'
image = cv2.imread(image_path)

# 调用 split_image 函数进行切图检测
split_frames, pred_results = split_image(image, model)

# 遍历切图并保存为图片文件
for i, split_frame in enumerate(split_frames):
    cv2.imwrite(f'split_image_{i}.jpg', split_frame)

# 遍历检测结果并输出到控制台
for pred in pred_results:
    x, y, x_, y_, conf, cls = pred
    print(f'Detected object: Class={cls}, Confidence={conf:.2f}, Bounding Box=({x}, {y}, {x_}, {y_})')
